home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5d9 / dcmds / C Samples / Drvr.c next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  5.7 KB  |  259 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Drvr.c
  3.  
  4.     Contains:    This is the Unit Table dcmd.
  5.  
  6.     Written by:    Scott Douglass, Dave Lyons
  7.  
  8.     Copyright:    © 1988,1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>     3/14/94    DAL        Re-layed-out the columns: removed Window and made room for
  13.                                     everything to be nice on 13" monitors. Made the "that's strange"
  14.                                     message not show up for dRef = 0xFFFE (.Sony for HD-20). Now
  15.                                     Hoon is happy.
  16.          <2>     9/14/93    DAL        made the driver name column wider
  17.  
  18.     Modification history:
  19.          7Dec88 sad        show driver version
  20.         29Nov88 sad        revised for new dcmd names
  21.         13Oct88 sad        written from file.c
  22.  
  23.     The following MPW commands will build the dcmd and copy it to the
  24.     "Debugger Prefs" file in the System folder. The dcmd's name in
  25.     MacsBug will be the name of the file built by the Linker.
  26.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  27.     C Samples folder into this folder.
  28.  
  29.     C Put.c
  30.     C Drvr.c
  31.     Link dcmdGlue.a.o Drvr.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Drvr
  32.     BuildDcmd Drvr 1000
  33.     Echo 'include "Drvr";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  34. */
  35.  
  36. #ifdef USESTDIO
  37.     #include <stdio.h>
  38. #endif
  39.  
  40. #include <Types.h>
  41. #include <Memory.h>
  42. #include <Devices.h>
  43. #include <SysEqu.h>
  44.  
  45. #include "dcmd.h"
  46. #include "put.h"
  47.  
  48.  
  49. typedef struct DRVR
  50. {
  51.     short drvrFlags;
  52.     short drvrDelay;
  53.     short drvrEMask;
  54.     short drvrMenu;
  55.     short drvrOpen;
  56.     short drvrPrime;
  57.     short drvrCtl;
  58.     short drvrStatus;
  59.     short drvrClose;
  60.     Str255 drvrName;
  61. } DRVR;
  62.  
  63.  
  64. static void DrawHdr()
  65. {
  66. //                    0         1         2         3         4         5         6         7         8         9
  67. //                    0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
  68.     dcmdDrawLine("\pdRef dNum Driver                      Flg  Ver   qHead   Storage Dely  Drvr at DCE at");
  69. }
  70.  
  71. #define kColumnNameEnd         37
  72. #define kColumnVersionEnd    46
  73. #define kColumnQHeadEnd        54
  74. #define kColumnStorageEnd    64
  75. #define kColumnDriverAtEnd    78
  76. #define kColumnDCEAtEnd        85
  77.  
  78.  
  79. static void DrawDCE(int dref, AuxDCE* dcep)
  80. {
  81.     DRVR*    drvrp;
  82.  
  83.     PutUHexWord(dref);
  84.     PutSpace();
  85.     PutUHexWord(~dref);
  86.     PutSpace();
  87.     if (dcep->dCtlFlags & 0x40)
  88.     {
  89.         if (dcep->dCtlDriver)
  90.         {
  91.             drvrp = * (DRVR **) dcep->dCtlDriver;
  92.             if (drvrp)
  93.                 PutPStrTruncTo(drvrp->drvrName, kColumnNameEnd);
  94.             else
  95.                 PutPStrTruncTo("\p-purged-", kColumnNameEnd);
  96.         }
  97.         else
  98.         {
  99.             PutPStrTruncTo("\p",kColumnNameEnd);
  100.         };
  101.     }
  102.     else
  103.     {
  104.         if (dcep->dCtlDriver)
  105.         {
  106.             drvrp = (DRVR*)dcep->dCtlDriver;
  107.             PutPStrTruncTo(drvrp->drvrName,kColumnNameEnd);
  108.         }
  109.         else
  110.         {
  111.             PutPStrTruncTo("\p",kColumnNameEnd);
  112.         };
  113.     };
  114.     PutSpace();
  115.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  116.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  117.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  118.     PutSpace();
  119.     PutUDecTo((unsigned char) dcep->dCtlQHdr.qFlags,kColumnVersionEnd);            // version
  120.     PutSpace();
  121.     PutUHexZTo((unsigned long) dcep->dCtlQHdr.qHead,8,kColumnQHeadEnd);            // qHead
  122.     PutSpace();
  123.     PutUHexZTo((unsigned long) dcep->dCtlStorage,8,kColumnStorageEnd);            // Storage
  124.     PutSpace();
  125.     PutUHexWord((unsigned long) dcep->dCtlDelay);
  126.     PutSpace();
  127.     PutUHexZTo((unsigned long) drvrp,8,kColumnDriverAtEnd);
  128.     PutSpace();
  129.     PutUHexZTo((unsigned long) dcep,8,kColumnDCEAtEnd);
  130.     PutLine();
  131.  
  132.     // For drvr FFFE (.Sony for the HD20, pre-SCSI), it's okay that
  133.     // the dCtlRefNum is $FFFB (don't whine about it)
  134.  
  135.     if ( (dref != dcep->dCtlRefNum) && ( ((unsigned short) dref) != (unsigned short) 0xFFFE) )
  136.     {
  137.         PutPStr("\p   that is strange:  dCtlRefNum = ");
  138.         PutUHexWord(dcep->dCtlRefNum);
  139.         PutLine();
  140.     }
  141. } // DrawDCE
  142.  
  143.  
  144. pascal void CommandEntry(dcmdBlock* paramPtr)
  145. {
  146.     switch (paramPtr->request)
  147.     {
  148.         case dcmdInit:
  149.             break;
  150.  
  151.         case dcmdHelp:
  152.             dcmdDrawLine("\pdrvr [refnum|num]");
  153.             dcmdDrawLine("\p   Displays driver information for the given refnum or all installed drivers.");
  154.             dcmdDrawLine("\p      Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  155.             break;
  156.  
  157.         case dcmdDoIt:
  158.         {
  159.             Boolean doOne = false;
  160.             long dref;
  161.             int NumDCEs;
  162.  
  163.             dcmdSwapWorlds();
  164.  
  165.             dcmdDrawLine("\pDisplaying Driver Control Entries");
  166.  
  167.             // get low-memory values after dcmdSwapWorlds()
  168.             NumDCEs = *(unsigned short *)UnitNtryCnt;
  169.  
  170.             (void)dcmdGetNextExpression(&dref, &doOne);
  171.  
  172.             if (doOne)
  173.             {
  174.                 int dnum;
  175.                 dref = (short)dref;
  176.                 if (dref < 0)
  177.                     dnum = ~dref;
  178.                 else
  179.                 {
  180.                     dnum = dref;
  181.                     dref = ~dref;
  182.                 }
  183.                 if (dnum > NumDCEs)
  184.                 {
  185. #ifdef USESTDIO
  186.                     Str255 line;
  187.                     sprintf(line,"Bad refnum 0x%.4x",(unsigned short)dref);
  188.                     dcmdDrawLine((Str255)c2pstr(&line));
  189. #else
  190.                     PutPStr("\pBad refnum ");
  191.                     PutUHexWord(dref);
  192.                     PutSpace();
  193.                     PutUHexWord(~dref);
  194.                     PutLine();
  195. #endif
  196.                 }
  197.                 else
  198.                 {
  199.                     AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
  200.                     if (dceh)
  201.                     {
  202.                         DrawHdr();
  203.                         DrawDCE(dref,*dceh);
  204.                     }
  205.                     else
  206.                     {
  207.                         PutPStr("\pDriver ");
  208.                         PutUHexWord(dref);
  209.                         PutSpace();
  210.                         PutUHexWord(~dref);
  211.                         PutPStr("\p is not in installed");
  212.                         PutLine();
  213.                     }
  214.                 }
  215.             }
  216.             else
  217.             {
  218.                 int DCEsUsed = 0;
  219.                 int dnum;
  220.                 AuxDCE*** dcehp;
  221.                 Boolean foundOne = false;
  222.                 for(dnum = 0, dcehp = *(AuxDCE****)UTableBase; dnum < NumDCEs; dnum++, dcehp++)
  223.                 {
  224.                     if (*dcehp)
  225.                     {
  226.                         DCEsUsed++;
  227.                         if (!foundOne)
  228.                         {
  229.                             DrawHdr();
  230.                             foundOne = true;
  231.                         }
  232.                         DrawDCE(~dnum,**dcehp);
  233.                     }
  234.                     if (paramPtr->aborted) break;
  235.                 }
  236.                 if(!paramPtr->aborted)
  237.                 {
  238.                     PutUDec(NumDCEs);
  239.                     PutPStr("\p Unit Table entries, ");
  240.                     PutUDec(DCEsUsed);
  241.                     PutPStr("\p in use, ");
  242.                     PutUDec(NumDCEs - DCEsUsed);
  243.                     PutPStr("\p free");
  244.                     PutLine();
  245.                 }
  246.             }    
  247.  
  248.             dcmdSwapWorlds();
  249.             break;
  250.         }
  251.  
  252.         default:
  253.             PutPStr("\punknown request ");
  254.             PutUDec(paramPtr->request);
  255.             PutLine();
  256.             break;
  257.     }
  258. }
  259.